﻿var desktop = {
    init: function() {
    	  	this.getMenuInfo();
            this.getUserInfo();      
            
    },
    //获取菜单列表
    getMenuInfo: function(event) {
        var url = "/bfs/bfs/menu/queryFirstMenu";       
        ajaxRequest(url, null, null, null,
            function(data) {                
        	    if (data.rows===null||data.rows.length===0) {
        	    	alert("对不起，你没有访问权限,请联系管理员。");
        	    	Logout();
        	    	return;
        	    }
        	    if (data.rows.length === 1) //如果只有一个子系统权限，自动跳转到该子系统
        	    {
        	    	window.location = "system.html?systemType="+data.rows[0].menuCode;
        	    	return;
        	    }
                ko.applyBindings(new desktop.viewModel(data.rows));
                $(".deskicon li").bind("click",function() {
                	var target = "system.html?systemType=" + $(this).attr("id");
                	window.location.href = target;
               	 //window.open("system.html?systemType="+$(this).attr("id"),"_blank");
               	 //window.location = "system.html?systemType="+$(this).attr("id");//如果不需要桌面导航页面，直接改为system.html页面即可    
               });
            },
            null);
    },
    //获取用户名
    getUserInfo: function() {
    	 var url = "/bfs/bfs/user/getUserInfo";       
         ajaxRequest(url, null, null, null,
             function(resp) {         	   
         	   $("#userName").text(resp.username).attr("title",resp.username);
             },
             null);
    },
    //视图模型
    viewModel: function(list) {
        this.meunList = list;
        console.log(this.meunList);
        this.logOut = desktop.logOut;
    },
    //退出
    logOut: function() {
    	Logout();
    }

};

$(function() {
	desktop.init();
});
